home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / MacApp / MacApp 2.0 CD Release / MacApp 2.0 (Many Libraries) / Interfaces / PInterfaces / UAssociation.p next >
Encoding:
Text File  |  1990-03-27  |  4.5 KB  |  139 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2. {UAssociation.p}
  3. {Copyright © 1988-1990 by Apple Computer Inc.  All rights reserved}
  4.  
  5. {$IFC UNDEFINED UsingIncludes}
  6. {$SETC UsingIncludes := FALSE}
  7. {$ENDC}
  8.  
  9. {$IFC NOT UsingIncludes}
  10. UNIT UAssociation;
  11.  
  12.     INTERFACE
  13.         {$ENDC}
  14.  
  15.         {$IFC UNDEFINED __UAssociation__}
  16.         {$SETC __UAssociation__ := FALSE}
  17.         {$ENDC}
  18.  
  19.         {$IFC NOT __UAssociation__}
  20.         {$SETC __UAssociation__ := TRUE}
  21.  
  22.         { • Auto-Include the requirements for this unit's interface }
  23.         {$SETC UAssociationIncludes := UsingIncludes}
  24.         {$SETC UsingIncludes := TRUE}
  25.         {$I+}
  26.         {$IFC UNDEFINED __UList__} {$I UList.p} {$ENDC}
  27.         {$SETC UsingIncludes := UAssociationIncludes}
  28.  
  29.         TYPE
  30.             TEntry                = OBJECT (TObject)        { This class has two instances variables to
  31.                                                          store a key string and an associated value
  32.                                                          string}
  33.  
  34.                 fKey:                StringHandle;        { A handle to the 'keyStr'}
  35.                 fValue:             StringHandle;        { A handle to the 'valueStr'}
  36.  
  37.                 PROCEDURE TEntry.IEntry(itsKey, itsValue: Str255);
  38.                 { Initialization routine}
  39.  
  40.                 PROCEDURE TEntry.Free; OVERRIDE;
  41.                 { Frees the fKey & fValue string handles then calls inherited free}
  42.  
  43.                 PROCEDURE TEntry.SetValue(VAR value: Str255);
  44.                 { Sets the fValue field to theValue}
  45.  
  46.                 PROCEDURE TEntry.Fields(PROCEDURE DoToField(fieldName: Str255;
  47.                                                             fieldAddr: Ptr;
  48.                                                             fieldType: INTEGER)); OVERRIDE;
  49.                 { Used by the Inspector and the Debugger to display the contents of this class's
  50.                 fields}
  51.  
  52.                 END;
  53.  
  54.             TEntriesList        = OBJECT (TSortedList)    { Subclass of TSortedList that manages a
  55.                                                          sorted list of TEntry objects, used as an
  56.                                                          instance variable in TAssociation}
  57.  
  58.                 PROCEDURE TEntriesList.IEntriesList;
  59.                 { Initialize the list }
  60.  
  61.                 FUNCTION TEntriesList.Compare(item1, item2: TObject): INTEGER; OVERRIDE;
  62.                 { Compares 'item'1 with 'item2' returning an integer indicating the results of the
  63.                     comparison}
  64.  
  65.                 PROCEDURE TEntriesList.Fields(PROCEDURE
  66.                                               DoToField(fieldName: Str255;
  67.                                                         fieldAddr: Ptr;
  68.                                                         fieldType: INTEGER)); OVERRIDE;
  69.                 { Used by the Inspector and the Debugger to display the contents of this class's
  70.                 fields }
  71.  
  72.                 END;
  73.  
  74.             TAssociation        = OBJECT (TObject)        { This class is used to create lists of
  75.                                                          strings that are accessed via their
  76.                                                          associated keys. The keys & strings are
  77.                                                          stored in TEntry objects which are in the
  78.                                                          TEntriesList instance variable}
  79.  
  80.                 fEntries:            TEntriesList;        { The list of TEntries that stores the
  81.                                                          associations }
  82.  
  83.                 PROCEDURE TAssociation.IAssociation;
  84.                 { Initialization routine  }
  85.  
  86.                 PROCEDURE TAssociation.Free; OVERRIDE;
  87.                 { Frees the instance variable fEntries }
  88.  
  89.                 FUNCTION TAssociation.ValueAt(keyStr: Str255;
  90.                                               VAR valueStr: Str255): BOOLEAN;
  91.                 { Given 'keyStr' returns the associated string in 'valueStr', with the result true
  92.                 if an associated string was found }
  93.  
  94.                 FUNCTION TAssociation.KeyAt(valueStr: Str255;
  95.                                             VAR keyStr: Str255): BOOLEAN;
  96.                 { Given 'valueStr' returns the associated key in 'keyStr', with the result true if
  97.                 an associated key was found }
  98.  
  99.                 PROCEDURE TAssociation.EachEntryDo(PROCEDURE
  100.                                                    DoToEntry(theEntry: TEntry));
  101.                 { Iterates over each entry passing it to "DoToEntry" }
  102.  
  103.                 FUNCTION TAssociation.EntryWithKey(keyStr: Str255): TEntry;
  104.                 { Returns the Entry containing 'keyStr' }
  105.  
  106.                 FUNCTION TAssociation.EntryWithValue(valueStr: Str255): TEntry;
  107.                 { Returns the entry containing 'valueStr' }
  108.  
  109.                 FUNCTION TAssociation.FirstEntryThat(FUNCTION
  110.                                                      TestEntry(theEntry: TEntry): BOOLEAN): TEntry;
  111.                 { Iterates over each entry passing it to "TestEntry" until the result of the Test is
  112.                 TRUE }
  113.  
  114.                 PROCEDURE TAssociation.InsertEntry(keyStr, valueStr: Str255);
  115.                 { Inserts an entry into thei association, if 'keyStr' already exists then the value
  116.                 is merely replaced with 'valueStr'. Otherwise a new Entry is created with the above
  117.                 'keyStr' and 'valueStr' }
  118.  
  119.                 PROCEDURE TAssociation.RemoveValueAt(keyStr: Str255);
  120.                 { Removes the value associated with 'keyStr' }
  121.  
  122.                 PROCEDURE TAssociation.RemoveKeyAt(valueStr: Str255);
  123.                 { Removes the key associated with 'valueStr' }
  124.  
  125.                 PROCEDURE TAssociation.Fields(PROCEDURE
  126.                                               DoToField(fieldName: Str255;
  127.                                                         fieldAddr: Ptr;
  128.                                                         fieldType: INTEGER)); OVERRIDE;
  129.                 { Used by the Inspector and the Debugger to display the contents of this class's
  130.                 fields }
  131.  
  132.                 END;
  133.  
  134.             {$ENDC}
  135.  
  136.             {$IFC NOT UsingIncludes}
  137. END.
  138. {$ENDC}
  139.